<?php

namespace app\common\customer\validate;

use app\common\system\logic\FormLogic;
use think\Validate;

class CustomerVisitValidate extends Validate
{
    protected $rule = [
        'member_id' => ['require', 'gt:0'],
        'status' => ['require'],
        'next_visit_time' => ['requireCallback:doCheckNextVisitTime'],
        'remark' => ['require', 'max:500'],
        'files' => ['array'],
        'images' => ['array'],
        'recording' => ['array'],
        // 'products' => ['requireCallback:checkProducts']
    ];

    protected $message = [
        'status.require' => '请选择回访状态',
        'next_visit_time.doCheckNextVisitTime' => '请选择下次回访时间',
        'member_id.require' => '参数错误',
        'remark.require' => '备注必填',
        'remark.max' => '备注最多500字',
        'files.array' => '附件字段格式不对',
        'images.array' => '凭证字段格式不正确',
        'recording.array' => '录音字段格式不正确',
        // 'products.array' => '标签数据格式不正确'
    ];

    protected function doCheckNextVisitTime($value, $data)
    {
        if (in_array($data['status'], ['2', '5', '8']) && empty($value)) {
            return false;
        }

        return false;
    }

    protected function checkProducts($value, $data)
    {
        if (in_array($data['status'], ['5', '8']) && empty($value)) {
            return false;
        }

        return true;
    }
}